<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 200px;
            height: 200px;
            background-color: aqua;
        }

        section {
            width: 100px;
            height: 100px;
            background-color: palevioletred;
        }
    </style>
</head>

<body>

    <div id="box">
        <section></section>
    </div>

    <script>
        let div = document.getElementById('box');
        box.onclick = function () {
            console.log(this);//box
            console.log(event.target);
        }

        function foo() {
            function fn() {
                console.log(this);
            }
            fn()
        }
        foo()

        let obj = {
            name: 'zhangdsan',
            show() {
                console.log(this);
                let fn = () => {
                    console.log(this);
                }
                fn()
            }
        }
        obj.show()


        let obj1 = {
            name1: function () {
                console.log(this);
            },
            obj2: {
                name2: function () {
                    console.log(this);
                },
                name3: () => {
                    console.log(this);
                },
                obj3: {
                    name4: function () {
                        console.log(this);
                    },
                    name5: () => {
                        console.log(this);
                    }
                }
            }
        }
        obj1.name1();
        obj1.obj2.name2();
        obj1.obj2.name3();
        obj1.obj2.obj3.name4();
        obj1.obj2.obj3.name5();
        //箭头函数没有this，当在箭头函数中去访问this会到它的上层作用域链中去找，
        //也就是包含它的函数中找，如果没有就是全局

        class Person {
            constructor(name, age, gender) {
                this.name = name;
                this.age = age;
                this.gender = gender;

            }
        }

        let user = new Person('zhangsan', 18, '男');
        console.log(user.__proto__ == Person.prototype);

        let user2 = Object.create(user);
        console.log(user2.__proto__);
        console.log(user);
        console.log(user2.name);
        console.log(Person.prototype.constructor);
        console.log(Person.__proto__===Function.prototype);
    </script>

</body>

</html>